<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

//Route::middleware('auth:api')->get('/user', function (Request $request) {
//    return $request->user();
//});
Route::prefix("v1")->namespace("Api")
    ->name("api.v1.")
    ->group(function () {
        //天津区域列表
        Route::get("areas","AreaController@index")
            ->middleware('throttle:' . config('api.rate_limits.list') . ',areas');;
        //接口调用频率限制
        Route::get("wechat_articles", "WechatArticleController@index");
        //商品列表
        Route::get("goodses", "GoodsController@index")
            ->name("goods.index")
            ->middleware('throttle:' . config('api.rate_limits.list') . ',goods_list');
        //产品详情
        Route::get("goods/{goodsId}", "GoodsController@show")
            ->name("goods.show")
            ->middleware('throttle:' . config('api.rate_limits.access') . ',goods_info');

        Route::get("wlgoods/{goodsId}", "WlGoodsController@show")
            ->name("wlgoods.show")
            ->middleware('throttle:' . config('api.rate_limits.access') . ',wlgoods_info');
        //商品类别
        Route::get("goods_category", "GoodsCategoryController@index")
            ->name("goods_category.index")
            ->middleware('throttle:' . config('api.rate_limits.access') . ',goods_category');
        //购物券的过期天数
        Route::get("pass_day", "IntegralRuleController@show")
            ->name("pass_day")
            ->middleware('throttle:' . config('api.rate_limits.access') . ',pass_day');
        //作家
        Route::get("authors", "AuthorController@index")
            ->name("authors.index")
            ->middleware('throttle:' . config('api.rate_limits.access') . ',authors');
        //单独作家详情
        Route::get("author/{authorId}", "AuthorController@show")
            ->name("author.show")
            ->middleware('throttle:' . config('api.rate_limits.access') . ',author');
        //作家作品列表
        Route::get("author/{author}/goods", "AuthorController@goods")
            ->name("author.goods")
            ->middleware('throttle:' . config('api.rate_limits.list') . ',authorGoods');

        //广告
        Route::get('ades', "AdController@index")
            ->name("ad.index")
            ->middleware('throttle:' . config('api.rate_limits.list') . ',ades');
        //多位置广告共同查找 暂时无用
        Route::get('ades_list', "AdController@list")
            ->name("ad.list")
            ->middleware('throttle:' . config('api.rate_limits.list') . ',ades_list');
        //专题详情
        Route::get('special_topic', 'SpecialTopicController@show')
            ->name("speclial_topic.show")
            ->middleware('throttle:' . config('api.rate_limits.access') . ',special_topic');

        //文章
        Route::get("articles", "ArticleController@index")
            ->name("article.index")
            ->middleware('throttle:' . config('api.rate_limits.list') . ',articles');
        //文章详情
        Route::get("article/{article_id}", "ArticleController@show")
            ->name("article.show")
            ->middleware('throttle:' . config('api.rate_limits.access') . ',article');

        //公司相关文章
        Route::get("company_article/{company_article_id}", "CompanyArticleController@show")
            ->middleware('throttle:' . config('api.rate_limits.access') . ',company_article');

        Route::get("company_phone","CompanyPhoneController@show")
            ->middleware('throttle:'.config('api.rate_limits.access').',company_phone');

        //展会信息
        Route::get("exhibition_info","ExhibitionController@show")
            ->middleware('throttle:' . config('api.rate_limits.access') . ',exhibition_info');
        //进行登录相关的频率限制，一分钟内仅可进行次操作
        //验证码生成 暂时无用
        Route::post("captchas", "CaptchasController@store")
            ->name("captchas.store");
        // 短信验证码
        Route::post('verificationCodes', 'VerificationCodesController@store')
            ->name('verificationCodes.store')
            ->middleware('throttle:' . config('api.rate_limits.sign') . ',verificationCodes');

        // 用户注册 暂时无用
        Route::post('users', 'UserController@store')
            ->name('users.store')
            ->middleware('throttle:' . config('api.rate_limits.sign') . ',users_register');
        //获取第三方的凭证
        Route::get('socials/{social_type}/appid', "AuthorizationsController@showAppid")
            ->where("social_type", "wechat|weimini")
            ->name("socials.authorizations.showAppid")
            ->middleware('throttle:' . config('api.rate_limits.sign') . ',social_type');
        // 第三方登录、注册
        Route::post('socials/{social_type}/authorizations', 'AuthorizationsController@socialStore')
            ->where('social_type', 'wechat|weimini')
            ->name('socials.authorizations.store')
            ->middleware('throttle:' . config('api.rate_limits.sign') . ',users_register');

        // 登录 暂时无用
        Route::post('authorizations', 'AuthorizationsController@store')
            ->name('authorizations.store')
            ->middleware('throttle:' . config('api.rate_limits.sign') . ',authorizations');
        // 刷新token
        Route::put('authorizations/current', 'AuthorizationsController@update')
            ->name('authorizations.update')
            ->middleware('throttle:' . config('api.rate_limits.sign') . ',refresh');
        //获取后台设定的活动相关规则
        Route::get("integralrules", "IntegralRuleController@index")
            ->name("integralrules")
            ->middleware('throttle:' . config('api.rate_limits.list') . ',integralrules');
        //首页每日首次访问的弹窗广告
        Route::get("alert_ad", "UserVisitLogController@show")
            ->name("ad.alert_ad")
            ->middleware('throttle:' . config('api.rate_limits.access') . ',alert_ad');


        //用户绑定手机号
        Route::post("user/phone_bind", "UserController@bing_phone")
            ->name("user.phone_bind")
            ->middleware('throttle:' . config('api.rate_limits.sign') . ',phone_bind');

        //发送微信推送
        Route::get("send_template_msg","ExhibitionController@send_template_msg")
            ->name("exhibition.send_msg");
        //获取会议签到二维码
        Route::get("exhibition_code","ExhibitionController@get_exhibition_code")
            ->name("exhibition.code")
            ->middleware('throttle:' . config('api.rate_limits.sign') . ',exhibition_code');
        //登录后才可访问的接口
        Route::middleware("auth:api")->group(function () {

            //通知统计
            Route::get('notifications/stats', 'NotificationsController@stats')
                ->name('notifications.stats')
                ->middleware('throttle:' . config('api.rate_limits.access') . ',notifications_count');

            //用户信息
            Route::get("user", "UserController@me")
                ->name("user.show")
                ->middleware('throttle:' . config('api.rate_limits.sign') . ',user_info');

            //用户积分
            Route::get('user/integral', "UserIntegralController@show")
                ->name("user.integral");
            //用户的积分分析 用于积分记录的内容
            Route::get("user/integral_composite", "UserIntegralController@show_detail")
                ->name("user.integral_log");
            //产品收藏
            Route::post("collection", "GoodsCollectionController@store")
                ->name("user.collection_store")
                ->middleware('throttle:' . config('api.rate_limits.list') . ',collection');
            //取消收藏
            Route::delete("collection", "GoodsCollectionController@destroy")
                ->name("user.collection_destroy")
                ->middleware('throttle:' . config('api.rate_limits.list') . ',collection');

            //用户的收藏列表
            Route::get("collections", "GoodsCollectionController@index")
                ->name("user.collections")
                ->middleware('throttle:' . config('api.rate_limits.list') . ',collections_list');


            //产品询价
            Route::post("ask_for_goods", "UserAskForGoodsController@store")
                ->name("user.ask_for_goods")
                ->middleware('throttle:' . config('api.rate_limits.list') . ',ask_for_goods');
            //猜你喜欢
            Route::get("guess_your_favourite", "UserController@guess_your_favourite")
                ->name("user.guess_your_favourite")
                ->middleware('throttle:' . config('api.rate_limits.list') . ',guess_your_favourite');

            Route::get("user_info", "UserController@show")
                ->name("user");
            //销售给客户新增积分变更记录
            Route::post("user_integral_log", "UserIntegralLogsController@store")
                ->name("user_integral_log.save")
                ->middleware('throttle:' . config('api.rate_limits.access') . ',user_integral_log_save');
            //销售给客户核销卡券
            Route::put("user/coupons/{coupon}", "CouponsController@update")
                ->name("coupons.patch");

            //积分使用情况
            Route::get("user_integral_logs", "UserIntegralLogsController@index")
                ->name("userintegrallogs.index")
                ->middleware('throttle:' . config('api.rate_limits.list') . ',userintegrallogs');
            //通知信息
            Route::get("notifications", "NotificationsController@index")
                ->name("notifications.index")
                ->middleware('throttle:' . config('api.rate_limits.list') . ',notifications_list');

            // 标记消息通知为已读
            Route::put('user/read/notifications', 'NotificationsController@read')
                ->name('user.notifications.read')
                ->middleware('throttle:' . config('api.rate_limits.access') . ',notifications_has_readed');


            //用户签到
            Route::post("registration", "SinInLogController@store")
                ->name("user.sign_in")
                ->middleware('throttle:' . config('api.rate_limits.sign') . ',registration');

            //秒杀处理
            Route::post("goods_seckill", "GoodsSeckillController@store")
                ->name("gooods.goods_seckill")
                ->middleware('throttle:' . config('api.rate_limits.sign') . ',goods_seckill');

            //积分兑换处理 //其实就是增加卡券
            Route::post("coupons", "CouponsController@store")
                ->name("coupons.store")
                ->middleware('throttle:' . config('api.rate_limits.sign') . ',coupons_store');
            //签到完毕之后判断是否发送礼品券
            Route::post("coupon", "CouponsController@check_coupons")
                ->name("coupon.check_coupons")
                ->middleware('throttle:' . config('api.rate_limits.sign') . ',check_coupons');

            Route::get("coupons", "CouponsController@index")
                ->name("coupon.index")
                ->middleware('throttle:' . config('api.rate_limits.list') . ',coupons');

            // 删除token
            Route::delete('authorizations/current', 'AuthorizationsController@destroy')
                ->name('authorizations.destroy');
            //查看外联产品
            Route::post("wlgoods_watchlog",'WlGoodsController@store_watch_log')
                ->name("wlgoods.watchlog");
            //会议签到
            Route::put("exhibition_arrived","ExhibitionController@store")
                ->name("exhibition.arrived");
        });

    });
